/*
 * Alloy Analyzer
 * Copyright (c) 2002 Massachusetts Institute of Technology
 *
 * The Alloy Analyzer is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * The Alloy Analyzer is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with the Alloy Analyzer; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

package alloy.bool;

/**
 * Visitor class for Boolean formulas.
 * <p>
 * Note that because some visitors store persistent state on the Boolean DAG
 * (notably the current values of Boolean {@linkplain BoolSwitch switches},
 * only one visitor at a time should be traversing a given Boolean DAG.
 */
abstract class GBF_V {
    /** Number of visitor objects created so far. */
    private static long _visitorsCreated = 0;

    /** Unique ID of this visitor. */
    private long _visitorId;
    
    protected GBF_V() { _visitorId = _visitorsCreated++; }

    protected boolean alreadyVisited(BooleanFormula node_)
    { return node_.lastVisitor != null && node_.lastVisitor.equals(this); }

    public boolean equals(Object that_) {
	return that_.getClass().equals(this.getClass()) &&
	    ((GBF_V)that_)._visitorId == this._visitorId;
    }

    abstract Object forLit(GBF_Lit g_lit);
    abstract Object forNot(GBF_Not g_not);
    abstract Object forAnd(GBF_And g_and);
    abstract Object forOr(GBF_Or g_or);
    abstract Object forConst(GBF_Const g_const);
    abstract Object forVarConst(VarConst varConst_);
    abstract Object forSetVarExpr(SetVarExpr setVarExpr_);
    abstract Object forCNFFunc(CNFFunc cnfFunc_);
}

 
